package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class SuperServlet
 */
@WebServlet("/MiCalculadora")
public class CalculadoraServlet extends HttpServlet {
	

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int v1 = Integer.parseInt(request.getParameter("v1"));
		int v2 = Integer.parseInt(request.getParameter("v2"));
		int op = Integer.parseInt(request.getParameter("selCombo"));
		PrintWriter writer = response.getWriter();
		if(op==1)
		{
			int suma=v1+v2;
			writer.println("<html>");
			writer.println("<head>");writer.println("</head>");
			writer.println("<body>");
			
			writer.println(v1+" + "+v2+" = "+suma);
			
			writer.println("</body>");
			writer.println("</html>");
		}
		if(op==2)
		{
			int resta=v1-v2;
			writer.println(v1+" - "+v2+" = "+resta);
		}
		if(op==3)
		{
			int multiplicacion=v1*v2;
			writer.println(v1+" * "+v2+" = "+multiplicacion);
		}
		if(op==4)
		{
			float division=v1/v2;
			writer.println(v1+" / "+v2+" = "+division);
		}
	}

}
